<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- STYLESHEETS -->
	<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
	<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
	<link rel="stylesheet" type="text/css" href="../../css/responsive.css">

	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">

	<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
	<link rel="stylesheet" href="../../js/datatables/datatable.css">
	<link rel="stylesheet" href="../../js/datepicker/datepicker.css">
	<style>
		/* .dataTables_scrollBody table td,
		.dataTables_scrollHeadInner table th {
			text-align: center;
		}
		.dataTables_scrollBody table tr td:last-child {
			text-align: left;
		}  */
	</style>
</head>

<body>
	<header class="navbar clearfix" id="header">
	</header>

	<!-- PAGE -->
	<section id="page">
		<!-- SIDEBAR -->
		<div id="sidebar" class="sidebar">
			<div class="sidebar-menu nav-collapse">

				<!-- SIDEBAR MENU -->
				<ul>

				</ul>
				<!-- /SIDEBAR MENU -->
			</div>

		</div>
		<!-- /SIDEBAR -->
		<div id="main-content">
			<!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
			<div class="modal fade" id="box-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
					<div class="modal-content" style="width:800px">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
							<h4 class="modal-title">维护库存</h4>
						</div>
						<div class="modal-body" style="display:inline">
							<div class="form-group" style="margin-bottom:10px">
								<label class="control-label col-md-2" style="line-height:34px;">商品名称：</label>
								<div class="col-md-10 productName" style="line-height: 34px">
								</div>
							</div>

							<div class="form-group divtiezhi houtai" style="margin-bottom:10px;height:60px">
								<label class="control-label col-md-2">库存信息：</label>
								<div class="col-md-10" style="display:inline-flex">
									<table class="table table-bordered">
										<thead>
											<tr>
												<th>SKU编码</th>
												<th>尺码</th>
												<th>库存</th>
											</tr>
										</thead>
										<tbody class="stock"></tbody>
									</table>

								</div>
							</div>

						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							<button type="button" class="btn btn-success bt-save">保存</button>
						</div>
					</div>
				</div>
			</div>
			<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- STYLER -->

									<!-- /STYLER -->
									<!-- BREADCRUMBS -->
									<ul class="breadcrumb">
										<li>
											<i class="fa fa-home"></i>
											<a href="../index.html">首页</a>
										</li>
										<li>
											<a href="#">商品管理</a>
										</li>
										<li>商品列表</li>
									</ul>
									<!-- /BREADCRUMBS -->

								</div>
							</div>
						</div>
						<!-- /PAGE HEADER -->
						<!-- FORMS QUERY-->
						<div class="row">
							<div class="col-md-12">
								<div class="row">
									<div class="col-md-12">
										<div class="box border primary">
											<div class="box-title">
												<h4><i class="fa fa-bars"></i>查询条件</h4>
											</div>
											<div class="box-body big" style="padding:10px;">
												<form class="form-horizontal" role="form" id='export_stock' action="../../admin/stock/exportStock.do">
													<div class="form-group mrg-bt10">
															<label class="col-sm-1 control-label">SKU编码：</label>
															<div class="col-sm-2" style="width:150px;">
																<input type="text" class="form-control" name="skuCode" placeholder="输入SKU编码">
															</div>
														<label class="col-sm-1 control-label">商品名称：</label>
														<div class="col-sm-2" style="width:150px;">
															<input type="text" class="form-control" name="productName" placeholder="输入商品名称">
														</div>
														<label class="col-sm-1 control-label">商品编码：</label>
														<div class="col-sm-2" style="width:150px;">
															<input type="text" class="form-control" name="productCode" placeholder="输入商品编码">
														</div>
														<label class="col-sm-1 control-label">库存小于：</label>
														<div class="col-sm-2" style="width:150px;">
															<input type="text" class="form-control" name="amount" onkeypress='return $.IsNum(event);' onblur='return $.IsNaN(this);'
															 placeholder="输入数字">
														</div>
														<div class="col-sm-2" style="width: 150px">
															<input type="checkbox" name="isYiigoo" style="margin-top: 10px">
															<span style="margin-left:10px; vertical-align: top;">是否为壹果商品</span>
														  </div>
														<div class="col-sm-1" style="width: 80px;">
																<a class="btn btn-primary search">查询</a>
															</div>
													</div>
												</form>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="modal fade" id="export-stock-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
						 aria-hidden="true">
							<div class="modal-dialog">
								<div class="modal-content">
									<div class="modal-header">
										<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
										<h4 class="modal-title">导出库存</h4>
									</div>
									<div class="modal-body">
										<form id='export_stock' action="../../admin/stock/exportStock.do" class="form-horizontal">
											<div class="form-group">
												<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>库存小于：</label>
												<div class="col-md-4">
													<input type="text" class="form-control" name="amount" placeholder="这里库存指花色库存"></textarea>
												</div>

											</div>
											<div class="form-group mrg-bt10">
												<label class="col-md-3 control-label" style="line-height:34px;">上新日期：</label>
												<div class="col-sm-8" style="display:inline-flex;margin-left:-10px">
													<div class="col-sm-4" style="width:130px">
														<input type="text" name="startDate" class="form-control bootstrap-datepicker">
													</div>
													<div style="width: 20px">至</div>
													<div class="float-left" style="width:130px">
														<input type="text" name="endDate" class="form-control bootstrap-datepicker">
													</div>
												</div>

											</div>
										</form>
									</div>

									<div class="modal-footer">
										<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
										<button type="button" class="btn btn-success bt-save">保存</button>
									</div>
								</div>
							</div>
						</div>
						<!-- /FORMS QUERY -->
						<div class="row" style="height: 30px;">
							<div class="col-md-12">
								<div class="box ">
									<!-- <a href="add_stock_white.html"  class="btn btn-success config">
											<i class="fa  fa-plus-square-o"></i> 库存同步设置
										</a> -->
									<a href="#" class="btn btn-success export-stock">
										<i class="fa  fa-plus-square-o"></i> 导出库存
									</a>

								</div>
							</div>
						</div>
						<div class="row">
							<!-- TABLES -->
							<div class="col-md-12">
								<!-- BOX -->
								<div class="box border primary">
									<div class="box-title">
										<h4><i class="fa fa-table"></i>商品数：<span id="total"></span>条</h4>

									</div>
									<div class="box-body">
										<table id="db_stock_list" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">

										</table>
									</div>
								</div>
								<!-- /BOX -->
							</div>
						</div>
						<!-- /TABLES -->


						<div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
						</div>
					</div><!-- /CONTENT-->
				</div>
			</div>
		</div>
	</section>
	<!--/PAGE -->
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY -->
	<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
	<!-- JQUERY UI-->
	<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
	<!-- BLOCK UI -->
	<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>

	<!-- AUTOSIZE -->
	<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
	<!-- spinner -->
	<script src="../../js/spinner/spin.js"></script>
	<!-- DATA TABLES -->
	<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
	<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
	<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
	<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
	<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>

	<!-- INPUT MASK -->
	<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
	<!--bootbox-->
	<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
	<!-- SELECT2 -->
	<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	<!-- UNIFORM -->
	<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>

	<!-- COOKIE -->
	<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="../../js/script.js"></script>
	<script src="../../js/common.js"></script>
	<script language="javascript" src="../../js/print/LodopFuncs.js"></script>
	<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
	<script>
		var ProductStock = function () {
			var $mainDataTable = null;


			var searchProductStock = function () {
				var productCode = $("input[name=productCode]").val();
				var productName = $("input[name=productName]").val();
				var isYiigoo = $("[name=isYiigoo]").prop("checked");
				var skuCode = $("input[name=skuCode]").val();
				var url = App.getContextPath() + "admin/stock/searchStockV2.do?productName=" + productName + "&productCode=" +
					productCode + '&skuCode=' + skuCode;
				if ($("[name=amount]").val() != "")
					url += "&amount=" + $("[name=amount]").val();
				if (isYiigoo) {
					url += "&supplierId=" + 1;
				}
				if ($mainDataTable) {
					$mainDataTable.api().ajax.url(url).load();
					return;
				}
				var dtSetting = $.dataTableSetting({
					"ajaxSource": url,
					"serverSide": true,
					"bFilter": false, // 去掉搜索框
					"bLengthChange": true, // 每页显示数量							
					"sScrollX": "100%",
					"sScrollXInner": "100%",
					"iDisplayLength": 25,

					"bSort": false,
					"aoColumns": [{
						"mDataProp": "productCode",
						"sTitle": "商品编码",
						"width": "6%"
					}, {
						"mDataProp": "productName",
						"sTitle": "商品名称",
						"width": "15%"
						//"render":function(data, type, row){
						//return "<div style='display: inline-flex'><div><img width=100 height=100 src="+getProductImage(row.productImg,"-200*200.jpg")+"></div><div><a href='"+App.getDomain()+"/product/product.html?productId="+row.productId+"' target='_blank'>"+row.productName+"</a><br></div></div>";
						//}
					}, {
						"mDataProp": "skuCode",
						"sTitle": "SKU编码",
						"width": "6%",
						"class": "skuCode"
					}, {
						"mDataProp": "size",
						"sTitle": "尺码",
						"width": "10%"
					}, {
						"mDataProp": "amount",
						"sTitle": "M站库存",
						"width": "6%",
						"class": "amount"
					}, {
						"mDataProp": "realAmount",
						"sTitle": "可发库存",
						"width": "6%",
						"class": "amount",
						"render": function (data, type, row) {
							return row.realAmount ? row.realAmount : 0;
						}
					}, {
						"mDataProp": "saleStatus",
						"sTitle": "状态",
						"width": "6%",
						"render": function (data, type, row) {
							return row.saleStatus == "OnSale" ? "上架" : "下架";
						}
					}, {
						"mDataProp": "isSyncDesc",
						"sTitle": "是否同步",
						"width": "6%",
						'class': 'isSyncDesc'
					}, {
						"sTitle": "操作",
						"width": "10%",
						"render": function (data, type, row) {
							var str = "<p class='btn-toolbar' style='margin:0px'>" +
								"<a class='btn btn-primary btn-xs bt-edit btn-width' style='width:60px' href='javascript:;' id=" + row.productId +
								" productName=" + row.productName + " productCode=" + row.productCode +
								"><i class='fa fa-pencil-square-o'></i>编辑</a>"
							if (row.isSync) {
								str += "<a class='btn btn-success btn-xs bt-sync btn-width' style='width:90px' href='javascript:;' id=" +
									row.skuCode + " sync='false'><i class='fa fa-pencil-square-o'></i>取消同步</a>";
							} else {
								str += "<a class='btn btn-info btn-xs bt-sync btn-width' style='width:90px' href='javascript:;' id=" +
									row.skuCode + " sync='true'><i class='fa fa-pencil-square-o'></i>设置同步</a>";
							}

							str += "</p>";

							return str;
						}
					}]
				});
				$mainDataTable = $("#db_stock_list").dataTable(dtSetting);
			};
			var editStock = function () {
				var id = $(this).attr("id");
				var name = $(this).attr("productName");
				var productCode = $(this).attr("productCode");
				var supplierId = $("[name=isYiigoo]").prop("checked") ? 1 : null ;
				var supplierName = $("#supplier_select option:selected").text();
				$.ajax({
					type: "post",
					url: App.getContextPath() + "admin/stock/getStockByProductId.do?productId=" + id + "&supplierId=" + 1,
					async: true,
					success: function (result) {
						if (result != null) {
							var skus = "";
							$.each(result.extra, function (index, item) {
								skus += '<tr class="stockInfo" style="height: 24px"><td class="skuCode" >' + item.skuCode + "</td><td>" +
									item.sizeName + "</td><td><input type='text' class='form-control' maxlength='5' value=" + item.stock.amount +
									" style='width:50px' onkeypress='return $.IsNum(event);' onblur='return $.IsNaN(this);' /></td></tr>";
							})

							$("#box-config").find(".stock").empty().append(skus);

							$("#box-config").find(".productName").html(name);
							$("#box-config").find(".supplierName").html(supplierName);
							$("#box-config").find("[name=supplierId]").val(supplierId);
							$("#box-config").modal("show");
							$("#box-config").find(".bt-save").unbind("click").bind("click", function () {
								var list = [];
								$(".stockInfo").each(function () {

									var stock = {};
									stock.skuCode = $(this).find(".skuCode").html();
									stock.id = id;
									stock.productCode = productCode;
									var amount = $(this).find("input").val();
									stock.amount = amount == "" ? 0 : amount;
									list.push(stock);
								});
								$.ajax({
									type: "post",
									url: App.getContextPath() + "admin/stock/updateStock.do",
									data: {
										stocks: JSON.stringify(list)
									},
									async: true,
									success: function (result) {
										//循环list 更新table 中的数据
										$.each(list, function (index, item) {
											$("#db_stock_list tbody tr").each(function () {
												if ($(this).find(".skuCode").html().trim() == item.skuCode) {
													$(this).find(".amount").html(item.amount);
												}
											});
										});
										$("#box-config").modal("hide");




									}
								});
							});

						}

					}
				});
			}
			var exportStock = function () {

				$("#export_stock").submit();

			}
			var setSync = function () {
				var skuCode = $(this).attr('id');
				var sync = $(this).attr('sync');
				var $this = $(this)
				$.ajax({
					type: "post",
					url: App.getContextPath() + "admin/stock/setSync.do",
					data: {
						skuCode: skuCode,
						sync: sync
					},
					async: true,
					success: function (result) {
						if (result.type == 'success') {
							var text = '';
							if (sync == 'true') {
								text = '同步'
								$this.removeClass('btn-info').addClass('btn-success').attr('sync','false').html("<i class='fa fa-pencil-square-o'> 取消同步</i>")
							} else {
								text = '不同步'
								$this.removeClass('btn-success').addClass('btn-info').attr('sync','true').html("<i class='fa fa-pencil-square-o'> 设置同步</i>")
							}
							$this.closest('td').siblings('.isSyncDesc').text(text)
						} else {
							$.alert(result.content)
						}
					}
				});
			}
			var printSku = function () {
				var productId = $(this).attr("id");

				var skuCode = $(this).attr("skuCode");
				var productName = $(this).attr("productName");
				var sizeName = $(this).attr("sizeName");
				var price = $(this).attr("price");
				var url = "http://m.yiigoo.com/cart/skucart.html?productId=" + productId + "&skuCode=" + skuCode;
				var LODOP;
				LODOP = getLodop();
				LODOP.PRINT_INIT("");

				LODOP.PRINT_INITA(-3, 0, 800, 600, "");
				LODOP.SET_PRINT_PAGESIZE(2, 700, 500, "");
				LODOP.ADD_PRINT_IMAGE(17, 8, 140, 45, "<img src='http://m.yiigoo.com/images/logo.png'/>");
				LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
				LODOP.ADD_PRINT_TEXT(25, 82, 80, 20, "壹果");
				LODOP.SET_PRINT_STYLEA(0, "FontName", "Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0, "FontSize", 11);
				LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
				LODOP.ADD_PRINT_BARCODE(48, 1, 194, 170, "QRCode", url);
				LODOP.ADD_PRINT_TEXT(198, 2, 161, 40, productName.trim());
				LODOP.SET_PRINT_STYLEA(0, "FontName", "Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
				LODOP.ADD_PRINT_TEXT(235, 0, 146, 20, sizeName);
				LODOP.SET_PRINT_STYLEA(0, "FontName", "Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);
				LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
				LODOP.ADD_PRINT_TEXT(235, 120, 44, 20, "￥" + price);
				LODOP.SET_PRINT_STYLEA(0, "FontName", "Noto Sans S Chinese Regular");
				LODOP.PREVIEW();




			}

			var printProduct = function () {
				var productId = $(this).attr("id");
				var productName = $(this).attr("productName");
				var price = $(this).attr("price");
				var url = "http://m.yiigoo.com/product/product.html?productId=" + productId + "&sourceCode=kuaishan";
				var LODOP;
				LODOP = getLodop();
				LODOP.PRINT_INITA(-3, 0, 800, 600, "");
				LODOP.SET_PRINT_PAGESIZE(2, 700, 500, "");
				LODOP.ADD_PRINT_IMAGE(17, 8, 140, 45, "<img src='http://m.yiigoo.com/images/logo.png'/>");
				LODOP.SET_PRINT_STYLEA(0, "Stretch", 2);
				LODOP.ADD_PRINT_TEXT(25, 82, 80, 20, "壹果");
				LODOP.SET_PRINT_STYLEA(0, "FontName", "Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0, "FontSize", 11);
				LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
				LODOP.ADD_PRINT_BARCODE(48, 1, 194, 170, "QRCode", url);
				LODOP.ADD_PRINT_TEXT(198, 0, 161, 40, productName.trim());
				LODOP.SET_PRINT_STYLEA(0, "FontName", "Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0, "FontSize", 8);

				LODOP.ADD_PRINT_TEXT(235, 1, 162, 20, "￥" + price);
				LODOP.SET_PRINT_STYLEA(0, "FontName", "Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
				LODOP.PRINTA();
			}

			return {

				init: function () {
					$("#status_select").select2();
					$.initDate($("#export_stock"), -30, 0);
					$.ajax({
						type: "post",
						url: App.getContextPath() + "admin/store/searchSupplierList.do",
						async: true,
						success: function (result) {
							if (result != null) {

								var option = "<option value='0'>选择店铺</option>";
								$.each(result, function (index, item) {
									option += "<option value='" + item.id + "'>" + item.supplierName + "</option>";
								});
								$("#supplier_select").empty().append(option);

								$("#supplier_select").select2();
								$("#supplier_select").select2('val', 1);

							}

						}
					});

					$(".search").click(searchProductStock);
					$(".export-stock").click(exportStock);
					searchProductStock();
					$("#db_stock_list").on("click", ".bt-edit", editStock);
					$("#db_stock_list").on("click", ".bt-sync", setSync);
					$("#db_stock_list").on("click", ".bt-print-sku", printSku);
					$("#db_stock_list").on("click", ".bt-print-product", printProduct);
				}
			}
		}();

		$(function () {
			$("#header").load("../head.html");
			App.init(); //Initialise plugins and elements	        
			ProductStock.init();

		});
	</script>
	<!-- /JAVASCRIPTS -->
</body>

</html>